package com.hjtech.base.base;


import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.hjtech.base.utils.ActivityManager;

/*
 * 项目名:    EasyPark
 * 包名       com.hjtech.easypark.common.base
 * 文件名:    BaseActivity
 * 创建者:    ZJB
 * 创建时间:  2017/6/20 on 14:15
 * 描述:     TODO
 */
public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity implements BaseView {

    protected P presenter;
    public Context context;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        context = this;
        ActivityManager.getAppInstance().addActivity(this);
        presenter = initPresenter();
    }

    @Override
    protected void onResume() {
        /**
         * 设置为横屏
         */
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        ActivityManager.getAppInstance().removeActivity(this);
        if (presenter != null) {
            presenter.detach();
        }
        super.onDestroy();
    }

    public abstract P initPresenter();

    /**
     * 沉浸式状态栏
     */
    public void transStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

    @Override
    public void showLoadingDialog(String msg) {

    }

    @Override
    public void dimissLoadingDialog() {

    }
}
